/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
 * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
 *
 *    Copyright 2016-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
 *    Copyright 2017 (c) Stefan Profanter, fortiss GmbH
 */

#ifndef UA_ACCESSCONTROL_DEFAULT_H_
#define UA_ACCESSCONTROL_DEFAULT_H_

#include <open62541/plugin/accesscontrol.h>
#include <open62541/server.h>

_UA_BEGIN_DECLS

typedef struct {
    UA_String username;
    UA_String password;
} UA_UsernamePasswordLogin;

typedef UA_StatusCode (*UA_UsernamePasswordLoginCallback)
    (const UA_String *userName, const UA_ByteString *password,
    size_t usernamePasswordLoginSize, const UA_UsernamePasswordLogin
    *usernamePasswordLogin, void **sessionContext, void *loginContext);

/**
 * \brief 默认访问控制。可以是匿名、用户名-密码或基于证书的登录方式。登录用户拥有所有访问权限。
 *
 *        该插件将 UserIdentityToken 存储在会话上下文中，因此该字段不可用于其他用途。
 *
 *        证书验证插件的生命周期已迁移至访问控制系统。因此，它最终会与 AccessControl 同步清理释放
 */
UA_EXPORT UA_StatusCode UA_AccessControl_default(UA_ServerConfig *config,
                                                 UA_Boolean allowAnonymous,
                                                 const UA_ByteString *userTokenPolicyUri,
                                                 size_t usernamePasswordLoginSize,
                                                 const UA_UsernamePasswordLogin *usernamePasswordLogin);

UA_EXPORT UA_StatusCode
UA_AccessControl_defaultWithLoginCallback(UA_ServerConfig *config,
                                          UA_Boolean allowAnonymous,
                                          const UA_ByteString *userTokenPolicyUri,
                                          size_t usernamePasswordLoginSize,
                                          const UA_UsernamePasswordLogin *usernamePasswordLogin,
                                          UA_UsernamePasswordLoginCallback loginCallback,
                                          void *loginContext);

_UA_END_DECLS

#endif /* UA_ACCESSCONTROL_DEFAULT_H_ */
